﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【出入库业务类型】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto出入库业务类型
    /// </summary>
    public abstract class AutoOperTypeMapping : BaseMapping<OperType, OperTypeModel, OperTypeFilterModel>
    {
        public AutoOperTypeMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override OperTypeModel Entity2Model(OperType entity)
        {
            OperTypeModel model = new OperTypeModel();

            model.OperTypeID = entity.OperTypeID;
            model.GroupInfoID = entity.GroupInfoID;
            model.InOutType = entity.InOutType;
            model.Name = entity.Name;
            model.IsInit = entity.IsInit;
            model.IsDelete = entity.IsDelete;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;
            model.UpdateUserID = entity.UpdateUserID;
            model.UpdateUserName = entity.UpdateUserName;
            model.UpdateDate = entity.UpdateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override OperType Model2Entity(OperTypeModel model)
        {
            OperType entity = new OperType();

            entity.OperTypeID = model.OperTypeID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.InOutType = model.InOutType;
            entity.Name = model.Name;
            entity.IsInit = model.IsInit;
            entity.IsDelete = model.IsDelete;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;
            entity.UpdateUserID = model.UpdateUserID;
            entity.UpdateUserName = model.UpdateUserName;
            entity.UpdateDate = model.UpdateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<OperType> FilterModel2Where(OperTypeFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._OperTypeID.HasValue)
            {
                where = where.And(x => x.OperTypeID == filterModel._OperTypeID.Value);
            }
            if (filterModel._OperTypeIDs.IsNotEmpty() && filterModel._OperTypeIDs.Count > 0)
            {
                where = where.And(x => filterModel._OperTypeIDs.Contains(x.OperTypeID));
            }
            if (filterModel._NotOperTypeIDs.IsNotEmpty() && filterModel._NotOperTypeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotOperTypeIDs.Contains(x.OperTypeID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //类型
            if (filterModel._InOutType.HasValue)
            {
                where = where.And(x => x.InOutType == filterModel._InOutType.Value);
            }
            if (filterModel._InOutTypes.IsNotEmpty() && filterModel._InOutTypes.Count > 0)
            {
                where = where.And(x => filterModel._InOutTypes.Contains(x.InOutType));
            }
            if (filterModel._NotInOutTypes.IsNotEmpty() && filterModel._NotInOutTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotInOutTypes.Contains(x.InOutType));
            }

            //名称
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            //是否为初始创建
            if (filterModel._IsInit.HasValue)
            {
                where = where.And(x => x.IsInit == filterModel._IsInit.Value);
            }
            if (filterModel._IsInits.IsNotEmpty() && filterModel._IsInits.Count > 0)
            {
                where = where.And(x => filterModel._IsInits.Contains(x.IsInit));
            }
            
            //是否删除
            if (filterModel._IsDelete.HasValue)
            {
                where = where.And(x => x.IsDelete == filterModel._IsDelete.Value);
            }
            if (filterModel._IsDeletes.IsNotEmpty() && filterModel._IsDeletes.Count > 0)
            {
                where = where.And(x => filterModel._IsDeletes.Contains(x.IsDelete));
            }
            
            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            //修改人姓名
            if (!string.IsNullOrEmpty(filterModel._UpdateUserName))
            {
                where = where.And(x => x.UpdateUserName.Contains(filterModel._UpdateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._UpdateUserNameEqual))
            {
                where = where.And(x => x.UpdateUserName == filterModel._UpdateUserNameEqual);
            }

            //修改时间
            if (filterModel._UpdateDate.HasValue)
            {
                where = where.And(x => x.UpdateDate == filterModel._UpdateDate.Value);
            }
            if (filterModel._UpdateDate_Begin.HasValue)
            {
                where = where.And(x => x.UpdateDate >= filterModel._UpdateDate_Begin.Value);
            }
            if (filterModel._UpdateDate_End.HasValue)
            {
                where = where.And(x => x.UpdateDate < filterModel._UpdateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

